﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JMY_Models;
using JMY_IDAL;
using System.Data.SqlClient;
using System.Data;
using Newtonsoft.Json;
namespace JMY_DAL
{
   public class FileSCDAL:JMY_IDAL.FileSCIDAL
    {
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=HospitalMessage;User ID=sa;password=19961218;");
        /// <summary>
        /// 添加医院套餐信息
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AddComboInfo(T_Doctor_Combo_Model m)
        {
            int i;
            try
            {
                conn.Open();
                string sql = string.Format("insert into T_Doctor_Combo values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", m.T_Combo_Name,m.T_Combo_picture,m.T_Combo_Price,m.T_Combo_Order_Num,m.T_Combo_Type_Sex,m.T_Combo_Type_Age,m.T_Combo_Type_Price,m.T_Combo_Docid);
                SqlCommand cmd = new SqlCommand(sql, conn);
                i = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return i;
        }

        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int FileAdd(T_File_Infos_Model m)
        {
            int i;
            try
            {
                conn.Open();
                string sql = string.Format("insert into T_File_Infos values('{0}','{1}',{2})", m.T_File_Name, m.T_File_Url,m.T_File_Type_id);
                SqlCommand cmd = new SqlCommand(sql, conn);
                i = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return i;

        }
        /// <summary>
        /// 文件显示信息
        /// </summary>
        /// <returns></returns>
        public List<T_File_Infos_Model> GetFileInfos()
        {
            string sql = "select * from T_File_Infos";
            SqlDataAdapter da = new SqlDataAdapter(sql,conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            var data = JsonConvert.DeserializeObject<List<T_File_Infos_Model>>(JsonConvert.SerializeObject(dt));
            return data;
        }

        

    }
}
